package com.loctek.importexport.loader;


import android.app.Activity;
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.loctek.importexport.R;

import java.io.File;


public class GlideImageLoader implements ImageLoader {

    @Override
    public void displayImage(Activity activity, String path, ImageView imageView, int width, int height, int type) {
        //type = 1 为视频文件
        if (1 == type) {
            RequestOptions options = new RequestOptions()
                    .error(R.drawable.ic_gallery_default)
                    .placeholder(R.drawable.ic_gallery_default);
            Glide.with(activity)
                    .load(Uri.fromFile(new File(path)))
                    .apply(options)
                    .into(imageView);
        } else {
            RequestOptions options = new RequestOptions()
                    .error(R.drawable.ic_gallery_default) //设置错误图片
                    .placeholder(R.drawable.ic_gallery_default)//设置占位图片
                    .diskCacheStrategy(DiskCacheStrategy.ALL);//缓存全尺寸

            Glide.with(activity)                             //配置上下文
                    .load(Uri.fromFile(new File(path)))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
                    .apply(options)
                    .into(imageView);
        }


    }


    @Override
    public void clearMemoryCache() {
    }
}
